package com.spzx.product.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.spzx.common.core.domain.R;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.domain.SkuStock;
import com.spzx.product.mapper.SkuStockMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "sku库存模块")
@RestController
@RequestMapping("/Stock")
public class SkuStockController {

    @Resource
    SkuStockMapper skuStockMapper;
    @InnerAuth
    @Operation(summary = "内部调用接口：根据skuId查询库存数据")
    @GetMapping("getSkuStock/{skuId}")
    public R<SkuStock> gettSkuStock(@PathVariable("skuId") Long skuId){
        //一个sku只有一个库存记录

        //生成的sql语句：select *from sku_stock where sku_id=#{skuid} and del_flag = 0 limit 0, 1;
        SkuStock sskuStock = skuStockMapper.selectOne(Wrappers.lambdaQuery(SkuStock.class)
                .eq(SkuStock::getSkuId,skuId)
                .last("limit 1"));
                return R.ok(sskuStock); 

    }

}
